<?php
if( ! defined('BASEPATH')) exit('No direct script access allowed');

class Notification_model extends CI_Model
{
	public function __construct()
	{
		parent::__construct();
	}
	
	public function create_notification($insert){
		$this->db->insert('project_notification',$insert);
	}
	
	public function get_all(){
		return $this->db->order_by('id','DESC')->get_where('project_notification',array('notify_to'=>$this->session->userdata('user_id')))->result();
	}
	
	public function get_project_notification_by_date($created_date){
		$this->db->select('*');
		$this->db->from('project_notification');
		$this->db->where('created_date',$created_date);		
		return $this->db->get()->result();
		
		//return $this->db->get_where('project_notification',array('project_id'=>$id))->result();
	}
	
	public function timeline_date($id){	
		$this->db->select('created_date,id');
		$this->db->from('project_notification');
		$this->db->where('project_id',$id);
		$this->db->group_by('created_date');
		$this->db->limit(2);
		$this->db->order_by('created_date','DESC');
		return $this->db->get()->result();		
	}
	
	public function timeline_date_more($last_id,$project_id){		
		$this->db->select('created_date,id');
		$this->db->from('project_notification');
		$this->db->where('project_id',$project_id);
		$this->db->where("id < $last_id");
		$this->db->group_by('created_date');
		$this->db->order_by('created_date','DESC');
		$this->db->limit(1);
		return $this->db->get()->result();
		//return $this->db->last_query();
		
	}
	
}


